﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="/static/js/common.js"></script>

    <style>
        /* 相片、签名、上传样式 */
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

            .avatar-uploader .el-upload:hover {
                border-color: #409EFF;
            }

        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }

        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }
    </style>
</head>

<body>

    <div id="app" v-cloak>
        <el-form label-position="right" :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px"
                 size="mini">

            <el-tabs v-model="activeName">
                <el-tab-pane label="用户管理" name="first">
                    <div class="popupW100">
                        <el-row>
                            <el-col :span="11">
                                <div class="elst-select-mini">
                                    <el-form-item prop="loginName">
                                        <el-input type="text" v-model="Form.loginName" autocomplete="off" size="mini">
                                            <template slot="prepend">
                                                {{user.loginName+mark.m}}
                                            </template>
                                        </el-input>
                                    </el-form-item>
                                </div>
                            </el-col>
                            <el-col :span="11" :offset="2">
                                <div class="elst-select-mini">
                                    <el-form-item>
                                        <el-input type="text" v-model="Form.name" autocomplete="off"
                                                  size="mini">
                                            <template slot="prepend">
                                                {{user.name+mark.m}}
                                            </template>
                                        </el-input>
                                    </el-form-item>
                                </div>
                            </el-col>

                        </el-row>
                        <el-row>
                            <el-col :span="11">
                                <div class="elst-select-mini">
                                    <el-form-item>
                                        <el-input size="mini">
                                            <template slot="prepend">
                                                <div> {{user.sex+mark.m}}</div>
                                            </template>
                                            <el-select @visible-change="visibleChange" v-model="Form.sysUserInfor.sex" slot="suffix"
                                                       :placeholder="user.sex">
                                                <el-option label="请选择" value=""></el-option>
                                                <el-option v-for="item in sex" :label="item.value" :value="item.key">
                                                </el-option>
                                            </el-select>
                                        </el-input>
                                    </el-form-item>
                                </div>
                            </el-col>
                            <!--工厂-->
                            <input-factorys-all :span="11" :offset="2" 
                                                @change="factorysChange"
                                                text="工作地点(工厂)"
                                                v-model="Form.sysUserInfor.workCompany"
                                                >

                            </input-factorys-all>
                        </el-row>

                        <el-row>
                            <el-col :span="11">
                                <div class="elst-select-mini">
                                    <el-form-item>
                                        <el-input type="text" v-model="Form.sysUserInfor.telephone" autocomplete="off"
                                                  size="mini">
                                            <template slot="prepend">
                                                联系电话
                                            </template>
                                        </el-input>
                                    </el-form-item>
                                </div>
                            </el-col>
                            <el-col :span="11" :offset="2">
                                <div class="elst-select-mini">
                                    <el-form-item>
                                        <el-input type="text" v-model="Form.sysUserInfor.workType" autocomplete="off"
                                                  size="mini">
                                            <template slot="prepend">
                                                从事工种
                                            </template>
                                        </el-input>
                                    </el-form-item>
                                </div>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="11">
                                <div class="elst-select-mini">
                                    <el-form-item>
                                        <div class="elst-select-mini">
                                            <el-input size="mini">
                                                <template slot="prepend">
                                                    {{"生日"+mark.m}}
                                                </template>
                                                <el-date-picker slot="suffix" v-model="Form.sysUserInfor.birthday"
                                                                value-format="yyyy-MM-dd" type="date" placeholder="选择日期">
                                                </el-date-picker>
                                            </el-input>
                                        </div>
                                        <!-- <span class="iputLineMust" v-if="Form.YearMonth.length<=0">
                                                    <img src="/static/images/exclamation.png" alt="">
                                                </span> -->
                                    </el-form-item>
                                </div>
                                <!-- <div class="elst-select-mini">
                                    <el-form-item label="生日">
                                        <el-date-picker v-model="Form.sysUserInfor.birthday" value-format="yyyy-MM-dd"
                                            type="date" placeholder="选择日期">
                                        </el-date-picker>
                                    </el-form-item>
                                </div> -->
                            </el-col>
                            <el-col :span="11" offset="2">
                                <div class="elst-select-mini">
                                    <el-form-item>
                                        <div class="elst-select-mini">
                                            <el-input size="mini">
                                                <template slot="prepend">
                                                    {{"入职日期"+mark.m}}
                                                </template>
                                                <el-date-picker slot="suffix" v-model="Form.sysUserInfor.joinDate"
                                                                value-format="yyyy-MM-dd" type="date" placeholder="选择日期">
                                                </el-date-picker>
                                            </el-input>
                                        </div>
                                        <!-- <span class="iputLineMust" v-if="Form.YearMonth.length<=0">
                                                            <img src="/static/images/exclamation.png" alt="">
                                                        </span> -->
                                    </el-form-item>
                                </div>
                                <!-- <div class="elst-select-mini" offset="2">
                                    <el-form-item label="入职日期">
                                        <el-date-picker v-model="Form.sysUserInfor.joinDate" value-format="yyyy-MM-dd"
                                            type="date" placeholder="选择日期">
                                        </el-date-picker>
                                    </el-form-item>
                                </div> -->
                            </el-col>
                        </el-row>

                    </div>

                    <div class="popupW100">

                        <el-row>
                            <el-col :span="11">
                                <div class="elst-select-mini">
                                    <el-form-item label="是否为双总部人员">
                                        <el-radio v-model="Form.sysUserInfor.isBoth" label="1">是</el-radio>
                                        <el-radio v-model="Form.sysUserInfor.isBoth" label="0">否</el-radio>
                                    </el-form-item>
                                </div>
                            </el-col>

                            <el-col :span="11" offset="2">
                                <div class="elst-select-mini">
                                    <el-form-item label="是否加入培训计划">
                                        <el-radio v-model="Form.sysUserInfor.isTrainPlan" label="1">是</el-radio>
                                        <el-radio v-model="Form.sysUserInfor.isTrainPlan" label="0">否</el-radio>
                                    </el-form-item>
                                </div>
                            </el-col>
                        </el-row>



                        <el-row>
                            <el-col :span="24">
                                <div class="elst-select-mini">
                                    <el-form-item>
                                        <div class="el-input--mini el-input-group">
                                            <div class="el-input-group__prepend">
                                                {{user.remarks+mark.m}}
                                            </div>
                                            <el-input class="el-textarea__inner" type="textarea"
                                                      v-model="Form.sysUserInfor.remark" autocomplete="off">
                                            </el-input>
                                            <!-- <span class="iputLineMust" v-if="Form.remarks.length<=0">
                                                        <img src="/static/images/exclamation.png" alt="">
                                                    </span> -->
                                        </div>
                                    </el-form-item>
                                </div>
                            </el-col>
                            <!-- <el-col :span="24">
                                        <el-form-item :label="user.remarks+mark.m" prop="remarks" class="inputTextarea">
                                            <el-input type="textarea" v-model="Form.sysUserInfor.remark" autocomplete="off">
                                            </el-input>
                                        </el-form-item>
                                    </el-col> -->
                        </el-row>

                    </div>
                    <el-row>
                        <el-col :span="11">
                            <div class="elst-select-mini">
                                <el-form-item label="相片">
                                    <el-upload class="avatar-uploader" :action="UploadFileApiUrl" name="files"
                                               :show-file-list="false" :on-success="photohandleAvatarSuccess"
                                               :before-upload="beforeAvatarUpload">
                                        <img v-if="Form.sysUserInfor.photoPath"
                                             :src="host + Form.sysUserInfor.photoPath" class="avatar">
                                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                    </el-upload>
                                </el-form-item>
                            </div>
                        </el-col>
                        <el-col :span="11" offset="2">
                            <div class="elst-select-mini">
                                <el-form-item label="签名">
                                    <el-upload class="avatar-uploader" :action="UploadFileApiUrl" name="files"
                                               :show-file-list="false" :on-success="signhandleAvatarSuccess"
                                               :before-upload="beforeAvatarUpload">
                                        <img v-if="Form.sysUserInfor.signPath" :src="host + Form.sysUserInfor.signPath"
                                             class="avatar">
                                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                    </el-upload>
                                </el-form-item>
                            </div>
                        </el-col>
                    </el-row>
                </el-tab-pane>
                <el-tab-pane label="保命条款信息" name="third">
                    <div class="popupW200">
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="是否遵守保命条款">
                                    <el-radio v-model="Form.sysUserInfor.isClause" label="1">是</el-radio>
                                    <el-radio v-model="Form.sysUserInfor.isClause" label="0">否</el-radio>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item :label="Form.sysUserInfor.clausePhonePath">
                                    <!-- <el-form-item label="保命条款信息"> -->
                                    <el-upload class="avatar-uploader" :action="UploadFileApiUrl" name="files"
                                               :show-file-list="false" :on-success="clausePhonehandleAvatarSuccess"
                                               :before-upload="beforeAvatarUpload">
                                        {{Form.sysUserInfor.clausePhonePath}}
                                        <img v-if="Form.sysUserInfor.clausePhonePath"
                                             :src="host + Form.sysUserInfor.clausePhonePath" class="avatar">
                                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                    </el-upload>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </div>
                </el-tab-pane>
                <el-tab-pane label="角色管理" name="role">
                    <el-row>
                        <el-col :span="24">
                            <el-transfer filterable :titles="['系统角色', '已有角色']" :button-texts="['到左边', '到右边']"
                                         v-model="Form.roleIdList" :data="roleList"></el-transfer>
                        </el-col>
                    </el-row>
                </el-tab-pane>
            </el-tabs>
            <el-row type="flex" justify="end">
                <el-form-item>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSubmit}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>
    </div>

    <script type="text/javascript">
        function verifyLoginName(rule, value, callback) {
            if (this.id === guidEmpty) {
                var url = "/api/user/VerifyLoginName?loginName=" + value
                myAjax("get", null, url, null, function (response) {
                    callback();
                }, false, function (response) {
                    callback(new Error(response.message));
                })
            }
            else
                callback();

        };
        var app = new Vue({
            value1: '',
            el: '#app',
            data: {
                //文件上传接口路径
                UploadFileApiUrl: API_UPLOADFILE_URL,
                //工作字典
                factory: [],
                //性别字典
                sex: [],
                //系统角色
                roleList: [],
                activeName: 'first',
                //页面
                Form: {
                    "loginName": "",
                    "sysUserInfor": {
                        "name": "",
                        "sex": "",
                        "birthday": null,
                        "telephone": null,
                        "workType": null,
                        "joinCompany": null,
                        "joinDate": null,
                        "workCompany":null,
                        "isBoth": null,
                        "isTrainPlan": null,
                        "isClause": null,
                        "clausePhone": guidEmpty,
                        "clausePhonePath": null,
                        "phoneID": guidEmpty,
                        "photoPath": "",
                        "signID": guidEmpty,
                        "signPath": "",
                        "remark": "",
                        "createFactory": null,
                    },
                    roleIdList: [],
                    "id": guidEmpty,
                },
                //表单验证
                rules: {
                    loginName: [
                        verification.NotNull,
                        { pattern: verification.StringLengthAtoB.t.format(2, 20), message: verification.StringLengthAtoB.m.format(5, 20), trigger: 'blur' },
                        { validator: verifyLoginName, trigger: 'blur' }
                    ],
                    NotNull: [
                        verification.NotNull
                    ]
                }
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                //提交数据
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            onSubmitForm(this, '/api/User/Save', mythis.Form);
                        } else {
                            //验证失败
                            return false;
                        }
                    });
                },
                getSysRoleList: function () {
                    var vueApp = this;

                    var apiUrl = "/api/role/GetRoleList/" + this.Form.sysUserInfor.workCompany;

                    myAjax("get", null, apiUrl, null, function (response) {
                        vueApp.roleList = response.data;
                    }, false);
                },
                //获取用户信息
                getData: function () {
                    getData(this, '/api/user/get?id=' + this.id);
                },
                //上传相片成功处理
                photohandleAvatarSuccess:function(res, file) {
                    var data = res.data;//成功后的业务数据
                    var fileModel = data[0];//第一个文件对象
                    this.Form.sysUserInfor.phoneID = fileModel.id;
                    this.Form.sysUserInfor.photoPath = downLoadPath(fileModel.id);
                },
                //上传签名成功处理
                signhandleAvatarSuccess:function(res, file) {
                    var data = res.data;//成功后的业务数据
                    var fileModel = data[0];//第一个文件对象
                    this.Form.sysUserInfor.signID = fileModel.id;
                    this.Form.sysUserInfor.signPath = downLoadPath(fileModel.id);
                },
                //上传保命信息
                clausePhonehandleAvatarSuccess:function(res, file) {
                    var data = res.data;//成功后的业务数据
                    var fileModel = data[0];//第一个文件对象
                    this.Form.sysUserInfor.clausePhone = fileModel.id;
                    this.Form.sysUserInfor.clausePhonePath = downLoadPath(fileModel.id);
                    console.log(Form.sysUserInfor.clausePhonePath);
                    console.log(host + this.Form.sysUserInfor.clausePhonePath);
                },
                //上传图片前校验
                beforeAvatarUpload:function(file) {
                    const isJPG = file.type === 'image/jpeg';
                    const isLt2M = file.size / 1024 / 1024 < 2;

                    if (!isJPG) {
                        this.$message.error('上传头像图片只能是 JPG 格式!');
                    }
                    if (!isLt2M) {
                        this.$message.error('上传头像图片大小不能超过 2MB!');
                    }
                    return isJPG && isLt2M;
                },
                factorysChange: function () {
                    this.getSysRoleList();
                }
            },
            mounted: function () {
                this.id = getUrlParam("id");
                this.getData();
                //调用API 一次性获取001(性别),9001(工厂)字典信息集合。
                var diclist = getDicDataArray(['001'])
                //获取下拉菜单内容
                this.sex = getDicDataFodDataList(diclist, '001');
            }
        });
    </script>
</body>

</html>